#include <stdio.h>
#include <string.h>
#include <stdlib.h>

void p1() {
    const int ratio = 60;
    int minutes;
    int hour, min;
    printf("please enter minutes:");
    scanf("%d", &minutes);
    while (minutes > 0) {
        hour = minutes / ratio;
        min = minutes % ratio;
        printf("%d hours, %d minutes\n", hour, min);
        printf("please enter minutes:");
        scanf("%d", &minutes);
    }
}

void p2() {
    const int interval = 10;
    int input;
    printf("enter a number:");
    scanf("%d", &input);
    int end = input + interval;
    while (input <= end) {
        printf("%d\t", input);
        input++;
    }
    printf("\n");
}

void p3() {
    int days;
    printf("enter days:");
    scanf("%d", &days);
    while (days > 0) {
        printf("%d days are %d weeks,%d days.\n", days, days / 7, days % 7);
        printf("enter days(<=0 to quit):");
        scanf("%d", &days);
    }
    printf("bye\n");
}

void p4() {
    const float rate_inch_cm = 2.54f;
    const int rate_feet_inch = 12;
    float height;
    printf("enter a height in cm:");
    scanf("%f", &height);
    while (height > 0.0f) {
        float inches = height / rate_inch_cm;
        int feet = (int) inches / rate_feet_inch;
        printf("%.1f cm = %d feet,%.1f inches.\n", height, feet, inches - feet * rate_feet_inch);
        printf("enter a height in cm(<=0 to quit):");
        scanf("%f", &height);
    }
    printf("bye\n");
}

void p5() {
    int count, sum, days;           /* declaration statement          */

    count = 0;                /* assignment statement           */
    sum = 0;
    printf("enter a days:");
    scanf("%d", &days);
    while (count++ < days)      /* while                          */
        sum = sum + count;    /*     statement                  */
    printf("sum = $%d\n", sum);/* function statement             */
}

void p6() {
    int count, sum, days;           /* declaration statement          */

    count = 0;                /* assignment statement           */
    sum = 0;
    printf("enter a days:");
    scanf("%d", &days);
    while (count++ < days)      /* while                          */
        sum = sum + count * count;    /*     statement                  */
    printf("sum = $%d\n", sum);/* function statement             */
}

void p7() {
    double value;
    printf("enter a number:");
    scanf("%lf", &value);
    printf("cube of %f = %f", value, value * value * value);
}

void p8() {
    int firstOperand, secondOperand;
    printf("Enter an integer to save as the second operand:");
    scanf("%d", &secondOperand);
    printf("Now Enter first operand:");
    scanf("%d", &firstOperand);
    while (firstOperand > 0 && secondOperand > 0) {
        printf("%d %% %d is %d\n", firstOperand, secondOperand, firstOperand % secondOperand);
        printf("Now Enter first operand(<=0 to quit):");
        scanf("%d", &firstOperand);
    }
    printf("bye\n");
}

int Temperatures() {
    const float s_hadd = 32.0;
    const float s_hmutiply = 9.0 / 5.0;
    const float s_kadd = 273.16;
    float s;
    printf("Enter 摄氏度(q或非数字退出):");
    if (scanf("%f", &s) != 1) {
        return 0;
    }
    printf("%.3f 摄氏度 = %.3f 华氏度 = %.3f 开氏度\n", s, s * s_hmutiply + s_hadd, s + s_kadd);
    return 1;
}

int main() {
//    p1();
//    p2.c();
//    p3();
//    p4();
//    p5();
//    p6();
//    p7();
//    p8();
//p9
    while (Temperatures()==1);
    printf("bye\n");
    return 1;
}